#include "persion.h"

int Person::setPersionName(const char* pN)
{
    delete[] PersionName;
    cout<<"set PersionName$$ "<<pN<<"\n";
    PersionName=new char[strlen(pN)+1];
    if(PersionName)
    {
        strcpy(PersionName,pN);
        return 0;
    }
    return 1;
}

int Person::setRecordA(const char* rA)
{
    delete[] RecordA;
    cout<<"set RecordA$$ "<<rA<<"\n";
    RecordA=new char[strlen(rA)+1];
    if(RecordA)
    {
        strcpy(RecordA,rA);
        return 0;
    }
    return 1;
}

int Person::setRecordB(const char* rB)
{
    delete[] RecordB;
    cout<<"set RecordB$$ "<<rB<<"\n";
    RecordB=new char[strlen(rB)+1];
    if(RecordB)
    {
        strcpy(RecordB,rB);
        return 0;
    }
    return 1;
}

Person::Person(const char* pN,const char* rA,const char* rB)
{
    cout<<"create PersionName$$ "<<pN<<"\n";
    PersionName=new char[strlen(pN)+1];
    if(PersionName) strcpy(PersionName,pN);

    cout<<"create RecordA$$ "<<rA<<"\n";
    RecordA=new char[strlen(rA)+1];
    if(RecordA) strcpy(RecordA,rA);

    cout<<"create RecordB$$ "<<rB<<"\n";
    RecordB=new char[strlen(rB)+1];
    if(RecordB) strcpy(RecordB,rB);
}

Person::Person()
{
    const char* pN="noname";
    const char* rA="0";
    const char* rB="0";

    cout<<"create PersionName$$ "<<pN<<"\n";
    PersionName=new char[strlen(pN)+1];
    if(PersionName) strcpy(PersionName,pN);

    cout<<"create RecordA$$ "<<rA<<"\n";
    RecordA=new char[strlen(rA)+1];
    if(RecordA) strcpy(RecordA,rA);

    cout<<"create RecordB$$ "<<rB<<"\n";
    RecordB=new char[strlen(rB)+1];
    if(RecordB) strcpy(RecordB,rB);
}

Person::Person(const Person& s)
{
    cout<<"create PersionName$$ "<<s.PersionName<<"\n";
    PersionName = new char[strlen(s.PersionName)+1];
    if(PersionName) strcpy(PersionName,s.PersionName);

    cout<<"create RecordA$$ "<<s.RecordA<<"\n";
    RecordA=new char[strlen(s.RecordA)+1];
    if(RecordA) strcpy(RecordA,s.RecordA);

    cout<<"create RecordB$$ "<<s.RecordB<<"\n";
    RecordB=new char[strlen(s.RecordB)+1];
    if(RecordB) strcpy(RecordB,s.RecordB);
}

void Person::outPut()const
{
    cout<<"PersionName: "<<PersionName<<"\n";
    cout<<"RecordA: "<<RecordA<<"\n";
    cout<<"RecordB: "<<RecordB<<"\n";
}

Person::~Person()
{
    cout<<"delete PersionName$$ "<<PersionName<<"\n";
    cout<<"delete RecordA$$ "<<RecordA<<"\n";
    cout<<"delete RecordB$$ "<<RecordB<<"\n";
    delete[] PersionName;
    delete[] RecordA;
    delete[] RecordB;
}
